const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
var WebpackMd5Hash = require('webpack-md5-hash');
var uglifyPlugin = new webpack.optimize.UglifyJsPlugin({ minimize: true });//代码压缩
var providePlugin = new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery', 'window.$': 'jquery' });//引入jquery

module.exports = {
    entry: {
        // app: './app', //编译的入口文件
        index: __dirname + '/src/index.js', //编译的入口文件
        siteList: __dirname + '/src/siteList.js', //编译的入口文件
        map: __dirname + '/src/map.js', //编译的入口文件
    },
    devServer: {
        contentBase: path.resolve(__dirname, 'dist'),
        port:8089,
        disableHostCheck: true        
    },
    //插件
    plugins: [
        // new CleanWebpackPlugin(['dist']),//清理DIST
        // new HtmlWebpackPlugin({
        //     // title: 'Output Management'

        //     filename: __dirname + '/index.html',
        //     template: __dirname + '/index.js',
        //     hash : true,
        //     inject : true,
        // }),
        
        // uglifyPlugin,
        providePlugin
    ],
    output: {
        // publicPath: path.resolve(__dirname, 'dist/'),
        publicPath:'./', //服务器根路径
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [{
            test: require.resolve('jquery'),
            use: [{
                loader: 'expose-loader',
                options: 'jQuery'
            }, {
                loader: 'expose-loader',
                options: '$'
            }]
        }, {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: "babel-loader",
            options: {
                presets: [
                    "es2015"
                ]
            }
        }, {
            test: /.(jpg|png)$/, /*解析图片*/
            use: [{
                loader:'url-loader',
                options:{
                    // publicPath:'/image/',
                    limit:8192,
                    name: 'image/[name].[ext]?[hash]'
                    
                }
            }]
        }, {
            test: /.css$/,
            use: [{
                loader: "style-loader"
            }, {
                loader: "css-loader",
                options: {
                    // modules: false
                }
            }, {
                loader: "postcss-loader"
            }]
        }, {
            test: /\.less$/,
            use: [
                {
                    loader: "style-loader"
                }, {
                    loader: "css-loader",
                    options: {
                        // modules: false
                    }
                }, {
                    loader: "postcss-loader"
                }, {
                    loader: "less-loader"
                }
            ]
        }]
    }
};
